
package com.unicom;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class appMain {

    static String inputfileName = "intput.txt";
    static String outputfileName = "output.txt";

    public static void extractImageUrl(StringBuilder output)
    {
        String fileName = "/Users/zhangjianming/workDir/woapp/4/mytest001/test001/doc/output.txt";
        fileName = "/applogs/temp/output2.txt";

        fileName = "/applogs/temp/"+outputfileName;

        SimpleDateFormat dateFormater = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        String timestamp = dateFormater.format(date);
        System.out.println("timestamp:"+timestamp);

        String imageUrl = "";
        String curId = "";

        String text = output.toString();
        String[] lines = text.split("\\n");
        for (String line : lines) {
            System.out.print(line);
            // 或者你可以在每次迭代时做其他事情
            {

                Pattern pattern = Pattern.compile("{imageUrl");
                Matcher matcher = pattern.matcher(line);

                if (matcher.find()) {
                    // 如果找到了匹配项，输出结果
                    System.out.println("找到了匹配项0：" + matcher.group());

                    // 获取所有匹配项的起始位置和结束位置
                    int startIndex = matcher.start();
                    int endIndex = matcher.end();
                    System.out.println("起始位置：" + startIndex);
                    System.out.println("结束位置：" + endIndex);

                    // 根据起始位置和结束位置提取子字符串
                    imageUrl = line.substring(endIndex+1, line.length()-1);
                    System.out.println("提取的子字符串为：" + imageUrl);
                } else {
                    System.out.println("未找到匹配项！imageUrl");

                    Pattern pattern2 = Pattern.compile("result");
                    Matcher matcher2 = pattern2.matcher(line);

                    if (matcher2.find()) {
// 如果找到了匹配项，输出结果
                        System.out.println("找到了匹配项1：" + matcher2.group());

                        // 获取所有匹配项的起始位置和结束位置
                        int startIndex = matcher2.start();
                        int endIndex = matcher2.end();
                        System.out.println("起始位置：" + startIndex);
                        System.out.println("结束位置：" + endIndex);

                        Pattern pattern3 = Pattern.compile("code");
                        Matcher matcher3 = pattern3.matcher(line);

                        if (line.length() >= endIndex+3+36 ) {
                            // 根据起始位置和结束位置提取子字符串
                            curId = line.substring(endIndex + 3, endIndex + 3 + 36);
                            System.out.println("提取的子字符串为：" + curId);
                        }
                    }
                }
            }
        }

        if (imageUrl!=null && imageUrl.length() > 10) {
            try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileName, true))) {
                String outStr = curId + ":" + imageUrl;

                writer.write(outStr);
                writer.newLine(); // 写入换行符，以便每行文本在新的一行

                System.out.println("文本成功写入文件。");
            } catch (IOException e) {
                System.out.println("写入文件时发生错误。");
                e.printStackTrace();
            }
        }

    }

    public static boolean runCommand(String command) throws IOException
    {
        // 要执行的shell命令
//        String command = "zgrep -B 3 '调用开放平台接口查询数字人列表返回，出参:{\"msg\":\"成功\",\"result\":\"a2d348d6-0882-4a3e-a6cc-82fd7209414d\",\"code\":\"000\",\"detail\":\"成功\"}'     /applogs/*/20230317/catalina.out-9090.2023-03-17.gz";

        boolean resValue = false;
        ProcessBuilder processBuilder = new ProcessBuilder();
        processBuilder.command("sh", "-c", command);

        try {
            Process process = processBuilder.start();

            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            StringBuilder output = new StringBuilder();
            String line;

            while ((line = reader.readLine()) != null) {
                output.append(line).append("\n");
            }

            if (output.length() > 100)
            {
                resValue = true;
            }

            extractImageUrl(output);

            int exitCode = process.waitFor();

            System.out.println("Exit Code: " + exitCode);
            System.out.println("Output:\n" + output.toString());

        } catch (InterruptedException e) {
            e.printStackTrace();
            return resValue;
        }

        return resValue;
    }

    public static boolean runCommandTest(String command) throws IOException
    {
        // 要执行的shell命令
//        String command = "zgrep -B 3 '调用开放平台接口查询数字人列表返回，出参:{\"msg\":\"成功\",\"result\":\"a2d348d6-0882-4a3e-a6cc-82fd7209414d\",\"code\":\"000\",\"detail\":\"成功\"}'     /applogs/*/20230317/catalina.out-9090.2023-03-17.gz";

        boolean resValue = false;
        ProcessBuilder processBuilder = new ProcessBuilder();
        processBuilder.command("sh", "-c", command);

        try {
            Process process = processBuilder.start();

            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            StringBuilder output = new StringBuilder();
            String line;

            while ((line = reader.readLine()) != null) {
                output.append(line).append("\n");
            }

            if (output.length() > 50)
            {
                resValue = true;
            }

            int exitCode = process.waitFor();

            System.out.println("Exit Code: " + exitCode);
            if (output.length() > 10) {
                System.out.println("找到 Output:\n" + output.toString());
            }
            else
            {
                System.out.println("没找到");
            }

        } catch (InterruptedException e) {
            e.printStackTrace();
            return resValue;
        }

        return resValue;
    }


    public static void main1110(String[] args) {

        SimpleDateFormat dateFormater = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        String timestamp = dateFormater.format(date);
        System.out.println("开始timestamp:"+timestamp);

        String filePath = "/Users/zhangjianming/workDir/woapp/4/mytest001/test001/doc/Result_24.txt";
        filePath = "/applogs/temp/"+inputfileName;
//        filePath = "/applogs/temp/test001.txt";
        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String line;
            StringBuilder output = new StringBuilder();
            while ((line = br.readLine()) != null) {

                if (line.length() > 100) {
                    System.out.println(line);
                    System.out.println("line.length():" + line.length());

                    String extractedSubstring = line.substring(33, line.length()-38);
                    byte[] utf8Bytes = extractedSubstring.getBytes("UTF-8");
                    String utf8Str = new String(utf8Bytes, "UTF-8");
                    System.out.println("提取的子字符串为：" + utf8Str);

//                    for (int i = 1; i <= 5; i++) {
//                        System.out.println("重试次数：" + i);
//                        if (runCommand(utf8Str))
//                        {
//                            break;
//                        }
//                    }


                }
            }


        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main99(String[] args) {
        String filePath = "/Users/zhangjianming/workDir/woapp/4/mytest001/test001/doc/Result_000.txt";
    //    filePath = "/applogs/temp/"+inputfileName;
//        filePath = "/applogs/temp/test001.txt";
        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String line;
            StringBuilder output = new StringBuilder();
            while ((line = br.readLine()) != null) {

                if (line.length() > 100) {
                    System.out.println("\n 输入:" +line);
                  //  System.out.println("line.length():" + line.length());

                    String extractedSubstring = line.substring(33, line.length()-38);
                    byte[] utf8Bytes = extractedSubstring.getBytes("UTF-8");
                    String utf8Str = new String(utf8Bytes, "UTF-8");
                    String newStr = utf8Str.replaceAll("\"\"", "\"");
                  //  System.out.println("提取的子字符串为：\n" + utf8Str);
                    System.out.println(newStr);

                    {

                        Pattern pattern = Pattern.compile("\"result\":");
                        Matcher matcher = pattern.matcher(newStr);

                        if (matcher.find()) {
                            // 如果找到了匹配项，输出结果
                            System.out.println("找到了匹配项：" + matcher.group());

                            // 获取所有匹配项的起始位置和结束位置
                            int startIndex = matcher.start();
                            int endIndex = matcher.end();
                            System.out.println("起始位置：" + startIndex);
                            System.out.println("结束位置：" + endIndex);

                            // 根据起始位置和结束位置提取子字符串
                            if (newStr.length() >= endIndex + 1 + 36) {
                                String result = newStr.substring(endIndex + 1, endIndex + 1 + 36);
                                System.out.println("提取的子字符串为：" + result);
                                String commandStr = "zgrep -B 0 -m 1 \'" + result + "\' /Users/zhangjianming/workDir/woapp/4/mytest001/test001/doc/test001.txt";
                                System.out.println("commandStr:" + commandStr);
                                 if (runCommandTest(commandStr))
                                 {
                                     System.out.println("存在");
                                 }
                                 else
                                 {
                                     System.out.println("不存在");
                                 }

                            }
                        }
                    }
                }
            }


        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main1112(String[] args) {

        if (args.length>=2) {
            inputfileName = args[0];
            outputfileName = args[1];
        }

        System.out.println("inputfileName:"+inputfileName);
        System.out.println("outputfileName:"+outputfileName);

        for (String arg : args) {
            System.out.println(arg);
        }
    }

    public static void main_ok(String[] args) {

        if (args.length>=2) {
            inputfileName = args[0];
            outputfileName = args[1];
        }

        System.out.println("inputfileName:"+inputfileName);
        System.out.println("outputfileName:"+outputfileName);

        for (String arg : args) {
            System.out.println(arg);
        }

        SimpleDateFormat dateFormater = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        String timestamp = dateFormater.format(date);
        System.out.println("开始timestamp:"+timestamp);

        String filePath = "/Users/zhangjianming/workDir/woapp/doc/Result_20.txt";
        filePath = "/applogs/temp/"+inputfileName;
//        filePath = "/applogs/temp/test001.txt";
        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String line;
            StringBuilder output = new StringBuilder();
            while ((line = br.readLine()) != null) {

                if (line.length() > 100) {
                    System.out.println(line);
                    System.out.println("line.length():" + line.length());

                    String extractedSubstring = line.substring(33, line.length()-38);
                    byte[] utf8Bytes = extractedSubstring.getBytes("UTF-8");
                    String utf8Str = new String(utf8Bytes, "UTF-8");
                    System.out.println("提取的子字符串为：" + utf8Str);

                    for (int i = 1; i <= 5; i++) {
                        System.out.println("重试次数：" + i);
                        if (runCommand(utf8Str))
                        {
                            break;
                        }
                    }


                }
            }


        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main000(String[] args) {

        SimpleDateFormat dateFormater = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        String timestamp = dateFormater.format(date);
        System.out.println("timestamp:"+timestamp);

        String filePath = "/Users/zhangjianming/workDir/woapp/4/mytest001/test001/doc/test001.txt";
//        filePath = "/applogs/temp/Result_20.txt";
        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String line;
            StringBuilder output = new StringBuilder();
            while ((line = br.readLine()) != null) {
                output.append(line).append("\n");
            }

            extractImageUrl(output);


        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static void main04(String[] args) {

        SimpleDateFormat dateFormater = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        String timestamp = dateFormater.format(date);
        System.out.println("timestamp:"+timestamp);

        String filePath = "/Users/zhangjianming/workDir/woapp/4/test001/doc/test001.txt";
//        filePath = "/applogs/temp/test001.txt";
        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String line;
            StringBuilder output = new StringBuilder();
            while ((line = br.readLine()) != null) {
                System.out.println(line);
//                output.append(line).append("\n");

                Pattern pattern = Pattern.compile("imageUrl");
                Matcher matcher = pattern.matcher(line);

                if (matcher.find()) {
                    // 如果找到了匹配项，输出结果
                    System.out.println("找到了匹配项0：" + matcher.group());

                    // 获取所有匹配项的起始位置和结束位置
                    int startIndex = matcher.start();
                    int endIndex = matcher.end();
                    System.out.println("起始位置：" + startIndex);
                    System.out.println("结束位置：" + endIndex);

                    // 根据起始位置和结束位置提取子字符串
                    String extractedSubstring = line.substring(endIndex+1, line.length()-1);
                    System.out.println("提取的子字符串为：" + extractedSubstring);
                } else {
                    System.out.println("未找到匹配项！imageUrl");

                    Pattern pattern2 = Pattern.compile("result");
                    Matcher matcher2 = pattern2.matcher(line);

                    if (matcher2.find()) {
// 如果找到了匹配项，输出结果
                        System.out.println("找到了匹配项1：" + matcher2.group());

                        // 获取所有匹配项的起始位置和结束位置
                        int startIndex = matcher2.start();
                        int endIndex = matcher2.end();
                        System.out.println("起始位置：" + startIndex);
                        System.out.println("结束位置：" + endIndex);

                        Pattern pattern3 = Pattern.compile("code");
                        Matcher matcher3 = pattern3.matcher(line);

                        // 根据起始位置和结束位置提取子字符串
                        String extractedSubstring = line.substring(endIndex+3, endIndex+3+36);
                        System.out.println("提取的子字符串为：" + extractedSubstring);
                    }

                }


            }


        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main02(String[] args) throws IOException {
        // 要执行的shell命令
        String command = "zgrep -B 3 '调用开放平台接口查询数字人列表返回，出参:{\"msg\":\"成功\",\"result\":\"a2d348d6-0882-4a3e-a6cc-82fd7209414d\",\"code\":\"000\",\"detail\":\"成功\"}'     /applogs/*/20230317/catalina.out-9090.2023-03-17.gz";

        ProcessBuilder processBuilder = new ProcessBuilder();
        processBuilder.command("sh", "-c", command);

        try {
            Process process = processBuilder.start();

            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            StringBuilder output = new StringBuilder();
            String line;

            while ((line = reader.readLine()) != null) {
                output.append(line).append("\n");
            }

            int exitCode = process.waitFor();

            System.out.println("Exit Code: " + exitCode);
            System.out.println("Output:\n" + output.toString());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


    // 方法1
    public static String subStrUtf8(String str, int beginIndex, int endIndex) {
        String subStr = "";
        try {
            int byteEndIndex = Math.min(str.length(), endIndex);
            int byteLen = 0;
            do {
                // 将要截取的子串长度减1，此处切记用 byteEndIndex--，而不是 --byteEndIndex
                subStr = str.substring(beginIndex, byteEndIndex--);

                // 更新subStr转为UTF-8的byte[]的长度
                byteLen = subStr.getBytes("UTF-8").length;

                // 只要byteLen大于最初想要截取的子串的值，则继续循环
            } while (byteLen > endIndex - beginIndex);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return subStr;
    }

    //方法2
    public static String subStrUtf8(String str, int subLen) {
        String subStr = "";
        try {
            int byteEndIndex = Math.min(str.length(), subLen);
            int byteLen = 0;
            do {
                // 将要截取的子串长度减1，此处切记用 byteEndIndex--，而不是 --byteEndIndex
                subStr = str.substring(0, byteEndIndex--);

                // 更新subStr转为UTF-8的byte[]的长度
                byteLen = subStr.getBytes("UTF-8").length;

                // 只要byteLen大于最初想要截取的子串的值，则继续循环
            } while (byteLen > subLen);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return subStr;
    }


    public static void extractTemplateId(String idStr ,String output)
    {
        String fileName = "/Users/zhangjianming/workDir/woapp/4/mytest001/test001/doc/output.txt";
        fileName = "/data/tomcat/temp/output.txt";

        fileName = "/data/tomcat/temp/"+outputfileName;

        SimpleDateFormat dateFormater = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        String timestamp = dateFormater.format(date);
        System.out.println("timestamp:"+timestamp);

        String line = output;

        System.out.print(output);
        // 或者你可以在每次迭代时做其他事情

            String target1 = "templateId:";
            String target2 = ",ttsText";

            String templateId = "";
            String veId = "";

            int startIndex = line.indexOf(target1) + target1.length();
            int endIndex = line.indexOf(target2, startIndex);

            System.out.println("startIndex:"+startIndex);
            System.out.println("endIndex:"+endIndex);

            if (startIndex != -1 && endIndex != -1) {
                String contentBetween = subStrUtf8(line,startIndex, endIndex);
                templateId = contentBetween;
                System.out.println(contentBetween);  // 输出: content between
            } else {
                System.out.println("One or both targets not found in the original string.");
            }

            String target3 = "veId:";
            String target4 = ",activityId";

            startIndex = line.indexOf(target3) + target3.length();
            endIndex = line.indexOf(target4, startIndex);

            System.out.println("startIndex:"+startIndex);
            System.out.println("endIndex:"+endIndex);

            if (startIndex != -1 && endIndex != -1) {
                String contentBetween = subStrUtf8(line,startIndex, endIndex);
                veId = contentBetween;
                System.out.println(contentBetween);  // 输出: content between
            } else {
                System.out.println("One or both targets not found in the original string.");
            }

            System.out.println("templateId:"+templateId);
            System.out.println("veId:"+veId);


        if (templateId!=null && templateId.length() > 10) {
            try (BufferedWriter writer = new BufferedWriter(new FileWriter(fileName, true))) {
                String outStr = idStr + ":" + veId + ":" + templateId;

                writer.write(outStr);
                writer.newLine(); // 写入换行符，以便每行文本在新的一行

                System.out.println("文本成功写入文件。");
            } catch (IOException e) {
                System.out.println("写入文件时发生错误。");
                e.printStackTrace();
            }
        }

    }

    public static void mainoo(String[] args) {

        SimpleDateFormat dateFormater = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        String timestamp = dateFormater.format(date);
        System.out.println("开始timestamp:"+timestamp);

        String filePath = "/Users/zhangjianming/workDir/woapp/4/mytest001/test001/doc/test002.txt";

        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String line;
            StringBuilder output = new StringBuilder();
            while ((line = br.readLine()) != null) {

                if (line.length() > 100) {
                    System.out.println(line);
                    System.out.println("line.length():" + line.length());

                    String extractedSubstring = line;
                    byte[] utf8Bytes = extractedSubstring.getBytes("UTF-8");
                    String utf8Str = new String(utf8Bytes, "UTF-8");
                    System.out.println("提取的子字符串为：" + utf8Str);

//                    extractTemplateId(utf8Str);
                }
            }


        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static boolean runCommand002(String idStr ,String command) throws IOException
    {
        // 要执行的shell命令
//        String command = "zgrep -B 3 '调用开放平台接口查询数字人列表返回，出参:{\"msg\":\"成功\",\"result\":\"a2d348d6-0882-4a3e-a6cc-82fd7209414d\",\"code\":\"000\",\"detail\":\"成功\"}'     /applogs/*/20230317/catalina.out-9090.2023-03-17.gz";

        boolean resValue = false;
        ProcessBuilder processBuilder = new ProcessBuilder();
        processBuilder.command("sh", "-c", command);

        try {
            Process process = processBuilder.start();

            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            StringBuilder output = new StringBuilder();
            String line;

            while ((line = reader.readLine()) != null) {
                output.append(line).append("\n");
            }

            if (output.length() > 100)
            {
                resValue = true;
            }

            extractTemplateId(idStr,output.toString());

            int exitCode = process.waitFor();

            System.out.println("Exit Code: " + exitCode);
            System.out.println("Output:\n" + output.toString());

        } catch (InterruptedException e) {
            e.printStackTrace();
            return resValue;
        }

        return resValue;
    }

    public static void main(String[] args) {

        if (args.length>=2) {
            inputfileName = args[0];
            outputfileName = args[1];
        }

        System.out.println("inputfileName:"+inputfileName);
        System.out.println("outputfileName:"+outputfileName);

        SimpleDateFormat dateFormater = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        String timestamp = dateFormater.format(date);
        System.out.println("开始timestamp:"+timestamp);

        String filePath = "/Users/zhangjianming/workDir/woapp/4/mytest001/test001/doc/result003.text";
        filePath = "/data/tomcat/temp/"+inputfileName;
//        filePath = "/data/tomcat/temp/result003.text";

        int index = 0;
        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String string;
            String line;
            StringBuilder output = new StringBuilder();
            while ((string = br.readLine()) != null) {

                if (string.length() > 100) {
                    System.out.println(string);

                    String idSubstring = string.substring(0, 4);

                    line = string.split(",")[1];

//                    System.out.println(line);

                    System.out.println(string.split(",")[1]);
                    System.out.println(string.split(",")[2]);

                    System.out.println("line.length():" + line.length());

                    System.out.println("idSubstring1:" + idSubstring);
                    String extractedSubstring = line;
                    byte[] utf8Bytes = extractedSubstring.getBytes("UTF-8");
                    String utf8Str = new String(utf8Bytes, "UTF-8");
                    System.out.println("cmd1:" + utf8Str);

                    runCommand002(idSubstring,utf8Str);

//                    System.out.println("提取的子字符串为：" + utf8Str);

                    index = index + 1;


                    line = string.split(",")[2];
                    System.out.println("line.length():" + line.length());

                    System.out.println("idSubstring2:" + idSubstring);
                     extractedSubstring = line;
                    byte[] utf8Bytes2 = extractedSubstring.getBytes("UTF-8");
                     utf8Str = new String(utf8Bytes2, "UTF-8");
                    System.out.println("cmd2:" + utf8Str);

                    System.out.println("index：" + index);
                    runCommand002(idSubstring,utf8Str);


                }
            }


        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public static void main1111(String[] args) {

        if (args.length>=2) {
            inputfileName = args[0];
            outputfileName = args[1];
        }

        System.out.println("inputfileName:"+inputfileName);
        System.out.println("outputfileName:"+outputfileName);

        SimpleDateFormat dateFormater = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        String timestamp = dateFormater.format(date);
        System.out.println("开始timestamp:"+timestamp);

        String filePath = "/Users/zhangjianming/workDir/woapp/4/mytest001/test001/doc/new-02.text";
  //      filePath = "/data/tomcat/temp/"+inputfileName;
//        filePath = "/data/tomcat/temp/result003.text";

        int index = 0;
        try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
            String string;
            String line;
            String line2;
            StringBuilder output = new StringBuilder();
            while ((string = br.readLine()) != null) {

                if (string.length() > 100) {
                    System.out.println(string);

                    line = string.split(",")[1];
                    line2 = string.split(",")[2];

                    System.out.println(line);
                    System.out.println(line2);

                    System.out.println("line.length():" + line.length());
                    String idSubstring = line.substring(0, 4);
                    System.out.println("idSubstring:" + idSubstring);
                    String extractedSubstring = line.substring(5, line.length());
                    byte[] utf8Bytes = extractedSubstring.getBytes("UTF-8");
                    String utf8Str = new String(utf8Bytes, "UTF-8");
                    System.out.println("cmd:" + utf8Str);

                    System.out.println("line.length():" + line2.length());
                    String idSubstring2 = line2.substring(0, 4);
                    System.out.println("idSubstring:" + idSubstring2);
                    String extractedSubstring2 = line2.substring(5, line2.length());
                    byte[] utf8Bytes2 = extractedSubstring.getBytes("UTF-8");
                    String utf8Str2 = new String(utf8Bytes, "UTF-8");
                    System.out.println("cmd:" + utf8Str2);

                    index = index + 1;

                    System.out.println("index：" + index);

                    for (int i = 1; i <= 2; i++) {
                        System.out.println("重试次数：" + i);
                        if (runCommand002(idSubstring,utf8Str))
                        {
                            break;
                        }
                    }


                }
            }


        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}